package com.leapp.sk.viewdelegate.adapter.personal

import android.content.Context
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideCircleTransform
import com.example.mvp.view.LKCircleImageView
import com.leapp.sk.R
import com.leapp.sk.bean.ConcatTeacherDataEntity

/**
 * 联系老师适配器视图托管类
 * @author  chaohaipeng  on 2018/8/8.
 */
class ContanctTecherAdapterDelegate :BaseAdapterDelegate(){
    private val mHeadRequestOptions = RequestOptions()
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_contanct_thecher
    }

    /**
     * 设置数据
     */
    fun setData(context: Context,data: ConcatTeacherDataEntity){
        val tv_act_contanct_tecaher_name = getView<TextView>(R.id.tv_act_contanct_tecaher_name)
        val tv_act_contanct_tecaher_class = getView<TextView>(R.id.tv_act_contanct_tecaher_class)
        val ima_act_contanct_avatar = getView<LKCircleImageView>(R.id.ima_act_contanct_avatar)
        tv_act_contanct_tecaher_name.text=data.nickName
        tv_act_contanct_tecaher_class.text=data.className
        setHead(context,data.avatar,ima_act_contanct_avatar)
    }
    /**
     * 设置头像和昵称
     */
    private fun setHead(context: Context, headUrl: String?, headImage: LKCircleImageView) {
        val tag = headImage.getTag(com.example.baselibrary.R.id.tag_head)
        if (tag == null || tag != headUrl) {
            val mRequestManager = Glide.with(context)
            mHeadRequestOptions.diskCacheStrategy(DiskCacheStrategy.NONE)
            mHeadRequestOptions.skipMemoryCache(true)
            mHeadRequestOptions.error(com.example.baselibrary.R.mipmap.icon_defout_head)
            mHeadRequestOptions.transforms(GlideCircleTransform(context))
            mRequestManager.load(headUrl)
                    .thumbnail(0.2f)
                    .apply(mHeadRequestOptions)
                    .into(headImage)
            headImage.setTag(com.example.baselibrary.R.id.tag_head, headUrl)

        }

    }
}